package com.example.ybg.demo;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Ybg on 2016/8/16.
 */
public class AppInfoService {
    public Context context;
    private PackageManager pm;
    public AppInfoService(Context context){
        this.context = context;
        pm = context.getPackageManager();
    }
    public List<Appinfo> getAppinfos(){
        List<Appinfo> appinfos = new ArrayList<Appinfo>();
        Appinfo appinfo;
        List<ApplicationInfo> applicationinfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
        for(ApplicationInfo info:applicationinfos){
            appinfo = new Appinfo();
            Drawable app_icon = info.loadIcon(pm);
            appinfo.setApp_icon(app_icon);

            String app_name = info.loadLabel(pm).toString();
            appinfo.setApp_name(app_name);

            appinfos.add(appinfo);
        }
        return appinfos;
    }
}
